<?php
declare (strict_types = 1);

namespace app\api\controller;
use app\common\business\User as UserBis;
class User extends AuthBase
{
    /**
     * index	GET	user	index
     */
    public function index(){
       $user = (new UserBis())->getNormalUserById($this->userId);
       $resultUser = [
        'id'=>$user['id'],   
        'uesrname'=>$user['username'],
        'sex'=>$user['sex']
       ];
       return show(config('status.success'),'OK',$resultUser);

    }
    /**
     * update	PUT	user/:id	update
     */
    public function update()
    {           
        $username = input('param.username','','trim');
        $sex = input('param.sex',0,'intval');
        $data=[
            'username'=>$username,
            'sex'=>$sex,
        ];
        $validate = (new \app\api\validate\User())->scene('update_user');
        if(!$validate->check($data)){
            return show(config('status.error'),$validate->getError());
        }
        $userBisObj = new UserBis();
        $user = $userBisObj->update($this->userId,$data);
     
        if(!$user){
            return show(config('status.error'),'更新失败');
        }
        return show(1,'ok');
    }
}
